<template>
  <div id="labreportitem">
    <vxe-toolbar perfect>
      <template #buttons>
        <vxe-button type="text" class="button-blue" icon="vxe-icon-save" content="保存" :loading="showLoading" @click="save('labreportform')"></vxe-button>
      </template>
    </vxe-toolbar>

    <el-scrollbar style="width: 100%; height: calc(100% - 40px)">
      <el-form ref="labreportform" :model="form" :rules="formRule" label-width="110px" class="form-input-m baseForm">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目归类" prop="itemClass">
              <el-select @keyup="keyupEnter($event,0)" ref="form0" v-model="form.itemClass" placeholder="请选择" style="width:200px">
                <el-option v-for="item in itemClassDict" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="英文缩写">
              <el-input @keyup="keyupEnter($event,1)" ref="form1" v-model="form.itemEnCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="项目代码" prop="itemNo">
              <el-input @keyup="keyupEnter($event,2)" ref="form2" v-model="form.itemNo" @blur="inputItemCodeCode()" :disabled="!IsEmpty(form.id)"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="中文名称" prop="itemNa">
              <el-input @keyup="keyupEnter($event,3)" ref="form3" v-model="form.itemNa" @blur="addInputCode()"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="英文名称">
              <el-input @keyup="keyupEnter($event,4)" ref="form4" v-model="form.itemEnName"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="输入码">
              <el-input @keyup="keyupEnter($event,5)" ref="form5" v-model="form.inputCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="报告代码" prop="reportCode">
              <el-input @keyup="keyupEnter($event,6)" ref="form6" v-model="form.reportCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结果类型">
              <el-select @keyup="keyupEnter($event,7)" ref="form7" v-model="form.itemKind" placeholder="请选择" style="width:200px">
                <el-option v-for="item in itemKindDict" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="小数位数" @keyup="keyupEnter($event,8)" ref="form8">
              <el-input-number @keyup="keyupEnter($event,8)" ref="form8" v-model="form.decPos" :min="0" :max="100" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="单位">
              <el-input @keyup="keyupEnter($event,9)" ref="form9" v-model="form.unit"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="仪器大类" prop="instrClass">
              <el-select @keyup="keyupEnter($event,10)" ref="form10" v-model="form.instrClass" placeholder="请选择" style="width:200px">
                <el-option v-for="item in instrClassDict" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="基础项目代码" prop="basItemCode">
              <el-input @keyup="keyupEnter($event,11)" ref="form11" v-model="form.basItemCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="报告单元" prop="rptGroup">
              <el-select @keyup="keyupEnter($event,12)" ref="form12" v-model="form.rptGroup" placeholder="请选择" style="width:200px">
                <el-option v-for="item in reportGroupDict" :key="item.rptGroup" :label="item.rptGroupName" :value="item.rptGroup" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item prop="seq" label="顺序">
              <el-input-number @keyup="keyupEnter($event,13)" ref="form13" v-model="form.seq" :min="1" :max="100000" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否通道号转译" prop="isTran">
              <el-switch v-model="form.isTran" inline-prompt active-text="是" inactive-text="否" active-value="1" inactive-value="0"></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-collapse v-model="activeNames" @change="handleCollapseChange">
          <el-collapse-item name="1">
            <template #title>
              <!-- 使用 el-divider 作为标题 -->
              <el-divider content-position="left"> <a>{{isExpanded==true?'展开':'隐藏'}}</a></el-divider>
            </template>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="价格">
                  <el-input v-model="form.price"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="默认取值">
                  <el-input v-model="form.defaultVal"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="申请项目">
                  <el-input v-model="form.feeCode"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="标准项目">
                  <el-input v-model="form.baseCode"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">

              <el-col :span="12">
                <el-form-item label="统计代码">
                  <el-input v-model="form.countCode"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="备注">
                  <el-input v-model="form.remark"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="测试方法">
                  <el-input v-model="form.testMethod"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="是否启用">
                  <el-radio-group v-model="form.enable">
                    <el-radio :label="1">启用</el-radio>
                    <el-radio :label="0">禁用</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>

            <!-- ---------------------------------------------------------------------------------------- -->
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="急诊申请项目">
                  <SelectDataList ref="erFeeitemRef" :url="'/lis/fee/item/findFeeItemList'" :displayField="[
                          { title: '编码', props: 'feeCode' }, //列标题
                          { title: '名称', props: 'feeName' }
                        ]" :placeholder="'请选择'" :inputKeyName="'keyWords'" @selectDataRow="erFeeitemSelect" @clearValue="clearerFeeitemName" @sliceValue="sliceErFeeitemHandler" v-model="form.erFeeitemName" :isPage="false" />
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="对照项目">
                  <SelectDataList ref="mapperItemRef" :url="'/lis/fee/item/findFeeItemList'" :displayField="[
                          { title: '编码', props: 'feeCode' }, //列标题
                          { title: '名称', props: 'feeName' }
                        ]" :placeholder="'请选择'" :inputKeyName="'keyWords'" @selectDataRow="mapperItemSelect" @clearValue="clearmapperItemName" @sliceValue="slicemapperItemHandler" v-model="form.mapperItemName" :isPage="false" />

                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="结果默认值1">
                  <el-input v-model="form.defValue1"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="结果默认值2">
                  <el-input v-model="form.defValue2"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="结果默认值3">
                  <el-input v-model="form.defValue3"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="计算用默认取值">
                  <el-input v-model="form.defCalcValue"></el-input>
                </el-form-item>
              </el-col>

            </el-row>
            <!-- <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="菌科(二级分类)">
              <el-input v-model="form.fungalFamily"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="菌属(三级分类)">
              <el-input v-model="form.fungalGenus"></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
            <!-- <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="默认药敏组合">
              <el-input v-model="form.defDrugComb"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="基因输入模板">
              <el-input v-model="form.geneInputTemp"></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
            <!-- <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="计算用默认取值">
              <el-input v-model="form.defCalcValue"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="Gram一级分类">
              <el-input v-model="form.gramType"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="WhoNet代码">
              <el-input v-model="form.whonetCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="默认文字结果标志">
                  <el-input v-model="form.defTextResultFlag"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="样本质量">
                  <el-input v-model="form.sampleQuality"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="编号归类">
                  <el-input v-model="form.numType"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="结果互认代码">
                  <el-input v-model="form.resultMutuCode"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="HIS对照代码">
                  <el-input v-model="form.hisItemCode"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="体检对照代码">
                  <el-input v-model="form.physItemCode"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="结果超出数">
                  <el-input v-model="form.outResultNum"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="结果超出稀释倍数">
                  <el-input v-model="form.outResultDiluFactor"></el-input>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="允许CV(%)">
                  <!-- <el-input v-model="form.allowCvPerct"></el-input> -->
                  <el-input-number v-model="form.allowCvPerct" :min="0" :max="100" :step="0.1" />
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="允许TEa(%)">
                  <!-- <el-input v-model="form.allowTeaPerct"></el-input> -->
                  <el-input-number v-model="form.allowTeaPerct" :min="0" :max="100" :step="0.1" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="工作量">
                  <el-input v-model="form.workLoad"></el-input>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="是否参与统计">
                  <el-radio-group v-model="form.isStatistics">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="是否报告">
                  <el-radio-group v-model="form.isReport">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="是否质控">
                  <el-radio-group v-model="form.isQc">
                    <el-radio :label="1">是</el-radio>
                    <el-radio :label="0">否</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </el-collapse-item>
        </el-collapse>
        <!-- 参考范围 -->
        <el-divider content-position="left">参考范围</el-divider>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="下限">
              <el-input v-model="form.lnum"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="上限">
              <el-input v-model="form.hnum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参考值">
              <!-- <el-input v-model="form.ref"></el-input> -->
              <vxe-textarea v-model="form.ref" style="width:100%;border-radius: 4px !important"></vxe-textarea>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="结果标志:  <下限">
              <el-select v-model="form.lflag" placeholder="请选择" clearable>
                <el-option v-for="item in [{code:'N',name:'阴性'},{code:'P',name:'阳性'}]" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label=">上限">
              <el-select v-model="form.hflag" placeholder="请选择" clearable>
                <el-option v-for="item in [{code:'N',name:'阴性'},{code:'P',name:'阳性'}]" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <span class="text-bold text-orange">默认【小于 下限】为阴性,【大于 上限】为阳性</span>
          </el-col>
        </el-row>
        <!-- ---------------------------------------------------------------------------------------- -->

        <el-divider content-position="left">计算项目</el-divider>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否计算项目">
              <el-checkbox v-model="form.isCalcItem" label="是否计算项目" :true-label='1' :false-label="0" :checked-value="1" :unchecked-value="0" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item label="计算公式">
              <el-input v-model="form.calcItemFormula" type="textarea" :disabled="!form.isCalcItem"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button class="button-blue" :disabled="!form.isCalcItem" @click="toggleItemCalcFormulaDialog('calcItemFormula')">公式向导</el-button>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item label="计算公式显示">
              <el-input v-model="form.calcItemDescription" readonly type="textarea" :disabled="!form.isCalcItem"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button class="button-blue" :icon="openhidePanel?'ArrowUp':'ArrowDown'" @click="openhidePanel=!openhidePanel">更多公式</el-button>
          </el-col>
        </el-row>
        <div v-if="openhidePanel">
          <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="结果1计算公式">
                <el-input v-model="form.result1Formula" type="textarea" :disabled="!form.isCalcItem"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button class="button-blue" :disabled="!form.isCalcItem" @click="toggleItemCalcFormulaDialog('result1Formula')">公式向导</el-button>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="结果2计算公式">
                <el-input v-model="form.result2Formula" type="textarea" :disabled="!form.isCalcItem"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button class="button-blue" :disabled="!form.isCalcItem" @click="toggleItemCalcFormulaDialog('result2Formula')">公式向导</el-button>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="结果3计算公式">
                <el-input v-model="form.result3Formula" type="textarea" :disabled="!form.isCalcItem"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button class="button-blue" :disabled="!form.isCalcItem" @click="toggleItemCalcFormulaDialog('result3Formula')">公式向导</el-button>
            </el-col>
          </el-row>
        </div>
        <!-- <el-row :gutter="20" class="saveBtnRow">
          <el-button type="primary" v-loading="showLoading" @click="save">保存</el-button>
        </el-row> -->
      </el-form>
    </el-scrollbar>
    <LabItemDictInfoCalcFormula ref="LabItemDictInfoCalcFormulaRef" :type="formulaType" @confirmFormula="confirmFormula" :formula="form[formulaType]" :rptGroup="form.rptGroup" :description="formulaType==='calcItemFormula'?form.calcItemDescription:''" />
  </div>
</template>

<script lang="ts" setup>
// 引入组件区 ==========
import { ref, reactive, onMounted, getCurrentInstance, watch } from 'vue';
import { VXETable } from 'vxe-table';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { AppStore } from '@/stores/store';
import { defineProps } from 'vue';
import LabItemDictInfoCalcFormula from '@/views/lab_sys/lab_set/LabItemDictInfoCalcFormula.vue';
import { IsEmpty } from '@/utils/common';
import SelectDataList from '@/components/SelectDataList.vue';
import VxePulldownSelection from '@/components/VxePulldownSelection.vue';
import { funBdsJsResult } from '@/utils/Expression'; //函数公式

// let props = defineProps<{
//   form: any,
// }>();

// 全局变量定义区 ==========
let props = defineProps({
  formProp: {}, //表单
  itemClassDict: Array as () => String[], //项目归类字段
  instrClassDict: Array as () => String[], //仪器大类字典
  reportGroupDict: Array as () => String[], //报告单元字典
  itemKindDict: Array as () => String[], //结果类型字典
  rptGroup: String
}) as any;
let openhidePanel = ref(false);/**展开隐藏更多公式面板 */
let store = AppStore();
let showLoading = ref(false); //保存加载状态
let { proxy }: any = getCurrentInstance();
let activeNames = reactive([]);
let form = reactive({
  id: '',
  creator: '',
  editor: '',
  createTime: '',
  editTime: '',
  delFlag: '',
  orgId: '',
  itemNo: '',
  basItemCode: '',
  itemName: '',
  itemEnName: '',
  itemEnCode: '',
  inputCode: '',
  remark: '',
  enable: 1,
  seq: 1,
  itemClass: '',
  instrClass: '',
  rptGroup: '',
  isTran: '0',
  poct: 1,
  itemKind: null,
  decPos: 0,
  unit: '',
  price: '',
  reportCode: '',
  feeCode: '',
  countCode: '',
  baseCode: '',
  testMethod: '',
  defaultVal: '',
  lnum: '',
  hnum: '',
  ref: '',
  lflag: '',
  hflag: '',
  erFeeitemCode: '',
  erFeeitemName: '',
  mapperItemCode: '',
  mapperItemName: ''
}) as any;

let formRule = {
  itemNo: [
    {
      required: true,
      message: '请输入项目代码',
      trigger: 'blur'
    }
  ],
  basItemCode: [
    {
      required: true,
      message: '请输入基础项目代码',
      trigger: 'blur'
    }
  ],
  itemName: [
    {
      required: true,
      message: '请输入项目名称',
      trigger: 'blur'
    }
  ],
  itemClass: [
    {
      required: true,
      message: '请输入项目归类',
      trigger: 'blur'
    }
  ],
  instrClass: [
    {
      required: true,
      message: '请输入仪器大类',
      trigger: 'blur'
    }
  ],
  rptGroup: [
    {
      required: true,
      message: '请输入报告单元',
      trigger: 'blur'
    }
  ],
  reportCode: [
    {
      required: true,
      message: '请输入报告代码',
      trigger: 'blur'
    }
  ]
};
let LabItemDictInfoCalcFormulaRef = ref(null);
let formulaType = ref('');
//属性监听
/**formProp属性监听*/
watch(
  () => props.formProp,
  (n, o) => {
    if (!IsEmpty(n)) {
      form = n;
    }
  },
  { immediate: true, deep: true }
);

defineExpose({
  initPage
});
// 方法定义区 =============
onMounted(() => {
  // if (props.formProp.id) {
  //   getReportItemInfo();
  // } else {
  //   let $form = proxy.$refs.labreportform;
  //   $form.resetFields();
  //   form.rptGroup = props.rptGroup;
  //   console.log('报告单元Id', props.rptGroup);
  // }
});

/**初始化 */
function initPage(obj: any) {
  form.rptGroup = obj.rptGroup;
  if (obj.formProp.id) {
    getReportItemInfo();
  } else {
    let $form = proxy.$refs.labreportform;
    $form.resetFields();
    form.rptGroup = obj.rptGroup;
    form.instrClass = obj.instrClass;
    form.itemClass = obj.itemClass;
    form.enable = 1;
  }
}
function getReportItemInfo() {
  // form = JSON.parse(JSON.stringify(props.form));
  form = props.formProp;
  form.decPos = parseInt(props.formProp.decPos, 10);
  // console.log('传过来的form表单',form)
  // console.log(props.form);
  // const url = '/lis/report/item/findReportItem';
  // proxy.$http
  //   //注意此处的数据条数
  //   .get(url, {
  //     params: { id: props.form.id }
  //   })
  //   .then((res: any) => {
  //     form = res.data;
  //     console.log(form);
  //   })
  //   .catch((err: any) => {
  //     // VxeMessage('获取获取当前字典的字段列表失败',VxeNotifyType.error)
  //   });
}
// 保存
function save(formName: any) {
  let $el = proxy.$refs[formName];
  /**计算项目种不允许自己计算自己 */
  try {
    if (form.isCalcItem && (form.isCalcItem === 1 || form.isCalcItem === '1')) {
      if (!IsEmpty(form.calcItemFormula) && form.calcItemFormula.indexOf(`[${form.itemNo}]`) > -1) {
        VxeMessage(`计算项目不允许有自身`, VxeNotifyType.error);
        return;
      }
    }
  } catch (error) {
    //
  }

  $el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    if (form.id) {
      showLoading.value = true;
      const url = '/lis/lab/item/editLabItemDict';
      proxy.$http
        .post(url, form)
        .then((res: any) => {
          showLoading.value = false;
          if (res.status.code == 1) {
            VxeMessage(res.status.msg, VxeNotifyType.success);
            proxy.$emit('editOrAddLabItemDict', res.data.id); //调用父组件方法 重新获取数据
          } else {
            VxeMessage(res.status.msg, VxeNotifyType.error);
            proxy.$emit('editOrAddLabItemDict', res.data.id); //调用父组件方法 重新获取数据
          }
        })
        .catch((err: any) => {
          showLoading.value = false;
          VxeMessage(err, VxeNotifyType.error);
        });
    } else {
      showLoading.value = true;
      const url = '/lis/lab/item/addLabItemDict';
      proxy.$http
        .put(url, form)
        .then((res: any) => {
          showLoading.value = false;
          if (res.status.code == 1) {
            VxeMessage(res.status.msg, VxeNotifyType.success);
            proxy.$emit('editOrAddLabItemDict', res.data.id); //调用父组件方法 重新获取数据
          } else {
            VxeMessage(res.status.msg, VxeNotifyType.error);
          }
        })
        .catch((err: any) => {
          showLoading.value = false;
          VxeMessage(err, VxeNotifyType.error);
        });
    }
  });
}
/**
 * 计算公式弹窗
 */
function toggleItemCalcFormulaDialog(t) {
  if (LabItemDictInfoCalcFormulaRef.value) {
    formulaType.value = t;
    LabItemDictInfoCalcFormulaRef.value?.toggleShowHide({ rptGroup: form.rptGroup });
  }
}
/**
 * 公式确认
 */
function confirmFormula(e) {
  form[e.type] = e.formula;
  if (e.type === 'calcItemFormula') {
    form['calcItemDescription'] = e.description;
  }
}

function erFeeitemSelect(row) {
  form.erFeeitemCode = row.feeCode;
  form.erFeeitemName = row.feeName;
}
function clearerFeeitemName() {
  form.erFeeitemCode = '';
  form.erFeeitemName = '';
}

function sliceErFeeitemHandler() {
  let newStr = form.erFeeitemName.slice(0, -1);
  form.erFeeitemName = newStr;
}

function mapperItemSelect(row) {
  form.mapperItemCode = row.feeCode;
  form.mapperItemName = row.feeName;
}
function clearmapperItemName() {
  form.mapperItemCode = '';
  form.mapperItemName = '';
}

function slicemapperItemHandler() {
  let newStr = form.erFeeitemName.slice(0, -1);
  form.mapperItemName = newStr;
}

let isExpanded = ref(false);
function handleCollapseChange(activeNames) {
  isExpanded.value = activeNames.includes('1');
}

function inputItemCodeCode() {
  form.itemEnName = form.itemNo;
  form.reportCode = form.itemNo;
  form.itemEnCode = form.itemNo;
  form.basItemCode = form.itemNo;
}
// 填写仪器名称 自动生成助记符
function addInputCode() {
  form.inputCode = funBdsJsResult('firstPinYinFun', form.itemNa);
}

//回车事件
function keyupEnter(e: any, index: any) {
  if (e.key == 'Enter') {
    if (index == 13) {
      index = 0;
      proxy.$refs[`form${index}`].focus();
    } else if (index == 12) {
      index = 1;
      proxy.$refs[`form${index}`].focus();
    } else {
      proxy.$refs[`form${index + 2}`].focus();
    }
  }
}

</script>
<style lang="scss" scoped>
#labreportitem {
  width: 100%;
  height: 100%;
  // 附加按钮间距
  .button-blue,
  .button-red {
    margin: 5px 0 5px 5px;
  }

  // 右侧基本信息表单
  .baseForm {
    .el-row {
      margin-left: 0 !important;
      margin-right: 0 !important;
    }
    .saveBtnRow {
      margin-left: 120px !important;
      margin-bottom: 5px;
    }
    .el-form-item--large {
      margin-bottom: 10px;
    }
    .el-radio {
      margin-right: 20px;
    }
  }
}

:deep(.vxe-input--inner) {
  border-radius: 4px !important;
}
</style>
